<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" href="static/css/tcommon.css" />
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>预警提示</title>
<style>
.content_table {
	border: 1px solid #8DB2E3
}

.content_table td {
	height: 24px;
	padding: 5px
}

.content_table {
	width: 100%;
	border-collapse: collapse
}

.grid th {
	background: #E7F3FE;
	height: 27px;
	line-height: 27px;
	border: 1px solid #8DB2E3;
	padding-left: 5px
}

.content_table td {
	border: 1px solid #8DB2E3;
	padding-left: 5px
}
</style>
</head>

<body>
<div class="content-container" data-options="region:'center'" >
<div class="panel-header"><div class="panel-title">现场安全预警</div></div>
		<table id="pro_table1" class="easyui-datagrid" style="height: 100%"></table>
	</div>
	<div id="_proDlg" class="easyui-dialog info_dialog" buttons="#pro-dlg-buttons"
		style="width: 800px; padding: 10px 20px; max-height: 80%; overflow-y: auto; top: 30px;" closed="true">
		<div class="title"></div>
		<form id="proFm" method="post">
			<div class="content_container">
				<table class="content_table" id="display_table">
				</table>
				<br>
				<div class="" id="attrs" style="width: 100%;"></div>
			</div>
		</form>
	</div>
	<div id="pro-dlg-buttons">
		<a href="# " class="easyui-linkbutton " onclick="savePro()">已处理</a>
		<a href="# " class="easyui-linkbutton btn-cancel " onclick="javascript:$('#_proDlg').dialog('close')">取消</a>
	</div>
</body>
<script>
	var currentPro;
	$(document).ready(function() {
		$('#pro_table1').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			//title : "现场安全预警",
			url : "warningSafe.do",
			method : 'get',
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'projectitemid',
				title : '项目名',
				width : '',
				formatter : function(value,row,index) {
					if (row.projectItem){
						return row.projectItem.name;
					}
				}
			},{
				field : 'inspectiondate',
				title : '巡检日期',
				width : '',
				formatter : formatDate
			},{
				field : 'other',
				title : '查看详情',
				width : '',
				formatter : function(value,row,index) {
					return '<a href="#" style="color:red;" onclick="displayAtt(' + index + ');">点击查看</a>';
				}
			} ] ]
		});
		
		$.ajax({
			type : 'GET',
			url : "inspectionitem",
			data : {status:2},
			contentType : "application/json",
			success : function(data) {
				items = data.rows;
				var html="";
				var _html="";
				$.each(items,function(i,val){
					if(val.type==0){
						html+='<tr><td style="width:95%;">'+val.content+'</td><td class="safe"><input type="hidden" class="itemid" value="'+val.id+'" /><input type="hidden" class="type" value="check" /><input class="easyui-checkbox content"/></td></tr>';
					}
					if(val.type==1){
						html+='<tr><td colspan=2 style="border-width: 0px 0px 0px 0px;" >'+val.content+'</td></tr><tr><td colspan=2 class="safe"  style="border-width: 0px 0px 1px 0px;"><input type="hidden" class="itemid" value="'+val.id+'" /><input type="hidden" class="type" value="text" /><input class="easyui-textbox content" data-options="multiline:true,required:true" style="width: 100%;height:50px;"/></td></tr>';
					}
					
					if(val.type==0){
						_html+='<tr><td style="width:95%;">'+val.content+'</td><td class="safe"><input type="hidden" class="'+val.id+'" /><input class="easyui-textbox content" data-options="readonly:true"/></td></tr>';
					}
					if(val.type==1){
						_html+='<tr><td colspan=2 style="border-width: 0px 0px 0px 0px;">'+val.content+'</td></tr><tr><td colspan=2 class="safe" style="border-width: 0px 0px 1px 0px;"><input type="hidden" class="'+val.id+'" /><input class="easyui-textbox content" data-options="multiline:true,readonly:true" style="width: 100%;height:50px;"/></td></tr>';
					}
				});
				html+='</tr><td colspan=2 style="text-align:center;">上传图片：<input class="easyui-filebox" data-options="prompt:\'添加图片\',buttonText:\'选择图片\',multiple:true,accept:\'image/*\'" id="images" name="images" style="width: 300px;"/></td></tr>';
				html+='</tr><td style="width:95%;">是否推送至预警</td><td><input type="checkbox" name="tosafe" id="tosafe" style="height:20px;"/></td></tr>';
				$('#content_table').append(html);
				$('#display_table').append(_html);
				$.parser.parse('#content_table');
				$.parser.parse('#display_table');
			},
			dataType : "json"
		});
	});

	function displayAtt(index){
		var row = $('#pro_table1').datagrid('getRows')[index];
		$.ajax({
			type : 'GET',
			url :  "selectTosafeInfo.do?inspectiondate="+row.inspectiondate,
			cache : false,
			processData : false,
			contentType : false,
			success : function(data) {
				if(data.length==0){
					$(".easyui-textbox").textbox('setValue',"");
					$(".easyui-checkbox").checkbox('uncheck');
					$("#proDlg").dialog('open').dialog('setTitle', '安全检查');
				}else{
					$.each(data,function(i,val){
						if(val.item.type==0){
							$("#display_table").find("."+val.item.id).next().textbox('setValue',val.content=="true"?"已检查":"未检查");
						}
						if(val.item.type==1){
							$("#display_table").find("."+val.item.id).next().textbox('setValue',val.content);
						}
					});
					var atts = data[0].attachments;
					var tb="";
					$.each(atts,function(i,val){
						tb+= '<div class="col-md-3" ><img onclick="window.open(\''+val.url+'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" style="width:150px;height:100px;" src="'+val.url+'" alt="查看全图">';
						tb+= '</div>';
					});
					$('#attrs').empty().html(tb);
					$("#_proDlg").dialog('open').dialog('setTitle', '安全检查');
				}
			},
			dataType : "json"
		});
	}
	function savePro() {
		if (!$("#proFm").form('validate'))
			return;
		currentPro.status=1;
		$.ajax({
			type : 'POST',
			url : "safetyinspectionUpdate.do",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.show({
						title : '保存',
						msg : '保存成功',
						timeout : 5000,
						showType : 'slide'
					});
					refreshProTable();
				}else{
					$.messager.alert('保存', '保存失败', 'error');
				}
				$('#_proDlg').dialog('close');
			},
			dataType : "json"
		});
	}
	function refreshProTable() {
		$('#pro_table1').datagrid('reload');
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(),month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(),hour = date.getHours(),min = date.getMinutes(),sec = date.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
</script>

</html>